home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 March / macformat-035.iso / Shareware City / Developers / ICAppSourceKit1.2 / ICFSSpecWhats.p < prev    next >
Encoding:
Text File  |  1995-11-07  |  4.8 KB  |  181 lines  |  [TEXT/CWIE]

  1. unit ICFSSpecWhats;
  2.  
  3. interface
  4.  
  5.     uses
  6.         ICWindowGlobals;
  7.  
  8.     function WhatOpenFSSpec (wt: WindowType; item: integer): OSErr;
  9.     function WhatFlushFSSpec (wt: WindowType; item: integer): OSErr;
  10.     function WhatClickFSSpec (wt: WindowType; item: integer; er: eventRecord): OSErr;
  11.  
  12. implementation
  13.  
  14.     uses
  15.         Folders, ToolUtils, Dialogs, Aliases,
  16.  
  17.         ICTypes, ICDialogs, ICMiscSubs, ICSubs, ICAPI, ICDocument {X}, ICKeys, ICGlobals, ICStandardFile;
  18.  
  19.     function GetVolumeStuff (name: str31; date: longInt; var vrn: integer): OSErr;
  20.         var
  21.             err: OSErr;
  22.             pb: HParamBlockRec;
  23.             s: str255;
  24.             pass, i: integer;
  25.     begin
  26.         for pass := 1 to 2 do begin
  27.             i := 1;
  28.             while true do begin
  29.                 pb.ioVolIndex := i;
  30.                 i := i + 1;
  31.                 pb.ioNamePtr := @s;
  32.                 s := '';
  33.                 err := PBGetVInfoSync(@pb);
  34.                 if err <> noErr then begin
  35.                     leave;
  36.                 end;
  37.                 if IUEqualString(name, s) = 0 then begin
  38.                     if (pass = 2) or (pb.ioVCrDate = date) then begin
  39.                         leave;
  40.                     end;
  41.                 end;
  42.             end;
  43.             if err = noErr then begin
  44.                 leave;
  45.             end;
  46.         end;
  47.         if err = noErr then begin
  48.             vrn := pb.ioVRefNum;
  49.         end;
  50.         GetVolumeStuff := err;
  51.     end;
  52.  
  53.     function WhatOpenFSSpec (wt: WindowType; item: integer): OSErr;
  54.         var
  55.             spec: handle;
  56.             valid: boolean;
  57.             loe: longInt;
  58.             changed: boolean;
  59.             attr: longint;
  60.             pb: CInfoPBRec;
  61.             modified: boolean;
  62.             fs: FSSpec;
  63.     begin
  64.         valid := false;
  65.         spec := nil;
  66.         modified := false;
  67.         if ICGetPrefHandle(GetInstance, windowinfo[wt].items[item]^.key, attr, spec) = noErr then begin
  68.             valid := true;
  69.         end;
  70.         ProcessAttributes(wt, item, attr);
  71.         if valid & (GetHandleSize(spec) < SizeOf(ICFileSpec)) then begin
  72.             valid := false;
  73.         end;
  74.         if valid then begin
  75.             if (ICFileSpecHandle(spec)^^.alias.aliasSize = 0) or not has_aliasMgr then begin
  76.                 if GetVolumeStuff(ICFileSpecHandle(spec)^^.vol_name, ICFileSpecHandle(spec)^^.vol_creation_date, fs.vRefNum) = noErr then begin
  77.                     fs.parID := ICFileSpecHandle(spec)^^.fss.parID;
  78.                     fs.name := ICFileSpecHandle(spec)^^.fss.name;
  79.                     if FSpGetCatInfo(fs, 0, pb) <> noErr then begin
  80.                         modified := true;
  81.                         valid := false;
  82.                     end;
  83.                 end else begin
  84.                     valid := false;
  85.                 end;
  86.             end else begin
  87.                 loe := Munger(spec, 0, nil, SizeOf(ICFileSpec) - SizeOf(AliasRecord), @loe, 0);
  88.                 if ResolveAlias(nil, AliasHandle(spec), fs, changed) <> noErr then begin
  89.                     modified := true;
  90.                     valid := false;
  91.                 end;
  92.             end;
  93.         end;
  94.         if not valid then begin
  95.             if (FindFolder(kOnSystemDisk, kDesktopFolderType, true, fs.vRefNum, fs.parID) = noErr) & (FSpGetCatInfo(fs, -1, pb) = noErr) then begin
  96.                 fs.vRefNum := pb.ioVRefNum;
  97.                 fs.parID := pb.ioDrParID;
  98.             end else begin
  99.                 fs.vRefNum := 0;
  100.                 fs.parID := 0;
  101.                 fs.name := '';
  102.             end; (* if *)
  103.         end;
  104.         DisposeHandle(spec);
  105.         windowinfo[wt].items[item]^.fss := fs;
  106.         windowinfo[wt].items[item]^.modified := modified;
  107.         SetDCtlTitle(windowinfo[wt].window, item, fs.name);
  108.         SetDCtlEnable(windowinfo[wt].window, item, not IsLocked(wt, item));
  109.         WhatOpenFSSpec := noErr;
  110.     end; (* WhatOpenFSSpec *)
  111.  
  112.     function WhatClickFSSpec (wt: WindowType; item: integer; er: eventRecord): OSErr;
  113.         var
  114.             err: OSErr;
  115.             fs: FSSpec;
  116.             dirID: longInt;
  117.     begin
  118.         er := er; { Unused }
  119.         err := ICStandardGetFolder(fs, dirID);
  120.         if err = noErr then begin
  121.             DirtyDocument;
  122.             windowinfo[wt].items[item]^.fss.vRefNum := fs.vRefNum;
  123.             windowinfo[wt].items[item]^.fss.parID := dirID;
  124.             windowinfo[wt].items[item]^.fss.name := '';
  125.             SetDCtlTitle(windowinfo[wt].window, item, fs.name);
  126.         end; (* if *)
  127.         WhatClickFSSpec := err;
  128.     end; (* WhatClickFSSpec *)
  129.  
  130.     function WhatFlushFSSpec (wt: WindowType; item: integer): OSErr;
  131.         var
  132.             alias: AliasHandle;
  133.             ifs: ICFileSpec;
  134.             pb: HParamBlockRec;
  135.             err: OSErr;
  136.             pos: longInt;
  137.     begin
  138.         err := noErr;
  139.         if not IsLocked(wt, item) then begin
  140.             ifs.fss := windowinfo[wt].items[item]^.fss;
  141.             alias := nil;
  142.             err := -1;
  143.             if has_aliasMgr then begin
  144.                 err := NewAlias(nil, ifs.fss, alias);
  145.             end;
  146.             if err <> noErr then begin
  147.                 alias := AliasHandle(NewHandle(sizeof(AliasRecord)));
  148.                 err := MemError;
  149.                 if err = noErr then begin
  150.                     alias^^.aliasSize := 0;
  151.                     alias^^.userType := OSType(0);
  152.                 end; (* if *)
  153.             end; (* if *)
  154.     
  155.             if err = noErr then begin
  156.                 pb.ioVRefNum := ifs.fss.vRefNum;
  157.                 pb.ioVolIndex := 0;
  158.                 pb.ioNamePtr := @ifs.vol_name;
  159.                 err := PBGetVInfoSync(@pb);
  160.                 if err = noErr then begin
  161.                     ifs.vol_creation_date := pb.ioVCrDate;
  162.                 end; (* if *)
  163.             end; (* if *)
  164.     
  165.             if err = noErr then begin
  166.                 pos := Munger(Handle(alias), 0, nil, 0, @ifs, SizeOf(ICFileSpec) - SizeOf(AliasRecord));
  167.                 err := MemError;
  168.             end; (* if *)
  169.     
  170.             if err = noErr then begin
  171.                 err := ICMapErr(ICSetPrefHandle(GetInstance, windowinfo[wt].items[item]^.key, ICattr_no_change, Handle(alias)));
  172.             end; (* if *)
  173.     
  174.             if alias <> nil then begin
  175.                 DisposeHandle(Handle(alias));
  176.             end; (* if *)
  177.         end;
  178.         WhatFlushFSSpec := err;
  179.     end; (* WhatFlushFSSpec *)
  180.  
  181. end. (* ICFSSpecWhats *)